jQuery.sysPlugin = {
    initSimpleSelect2: function (target) {
        (target == undefined ? $("select") : target).select2({
            minimumResultsForSearch: Infinity,
            width: '100%'
        });
    },
    initDateTimeInput: function () {
        $('.timeInput').datetimepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            weekStart: 1,
            todayBtn: 1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 2,
            todayHighlight: true,
            forceParse: 0
        }).on("changeDate", function (ev) {

            try {
                $(this).parents("form").bootstrapValidator('revalidateField', $(this).find("input").attr("name"));
            } catch (e) {
            }


        });
    },
    int2DateString: function (value) {
        if (value == undefined || value == "") {
            return "";
        }
        var dt = new Date(parseInt(value));
        var data = dt.getFullYear()
            + "-"
            + ((dt.getMonth() + 1) >= 10 ? (dt.getMonth() + 1) : "0"
            + (dt.getMonth() + 1))
            + "-"
            + (dt.getDate() < 10 ? "0" + dt.getDate() : dt.getDate());
        return data;
    },
    int2DateTimeString: function (value) {
        if (value == undefined || value == "") {
            return "";
        }
        var date = new Date(parseInt(value));
        var datetime = date.getFullYear()
            + "-"
            + ((date.getMonth() + 1) >= 10 ? (date.getMonth() + 1) : "0"
            + (date.getMonth() + 1))
            + "-"
            + (date.getDate() < 10 ? "0" + date.getDate() : date
                .getDate())
            + " "
            + (date.getHours() < 10 ? "0" + date.getHours() : date
                .getHours())
            + ":"
            + (date.getMinutes() < 10 ? "0" + date.getMinutes() : date
                .getMinutes())
            + ":"
            + (date.getSeconds() < 10 ? "0" + date.getSeconds() : date
                .getSeconds());
        return datetime;
    },
    //创建弹框字符串
    createAlert: function (message) {
        return '<div  class="alert alert-danger alert-dismissible " role="alert" >' +
            '<button type="button" class="close" data-dismiss="alert">' +
            '<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>' +
            '</button>' +
            '<label>' + message + '</label>' +
            '</div>';
    },
    superAjax: function (var_arg) {
        var arg = {
            url: '#',
            data: {},
            type: 'POST',
            contentFile: false,
            operateType: 'other',
            showSuccessAlert: true,
            showWarnAlert: true,
            successCall: function (data) {
            },
            errorCall: function (data) {
            },
            completeCall: function (data) {
            }
        };
        jQuery.extend(arg, var_arg);
        if (arg.operateType == 'insert') {
            arg.operateType = '添加'
        } else if (arg.operateType == 'update') {
            arg.operateType = '修改';
        } else if (arg.operateType == 'delete') {
            arg.operateType = '删除';
        } else if (arg.operateType == 'other') {
            arg.operateType = '操作';
        } else {
            alert(arg.operateType + " 不是add、update、delete、other中的任何一个");
            return;
        }
        var i = {
            type: arg.type,
            data: arg.data,
            url: arg.url,
            success: function (data) {
                if (typeof data.code == 'undefined') {
                    window.document.write(data);
                }
                if (data.code == 'zj001') {
                    if (arg.showSuccessAlert) {
                        swal({
                            title: arg.operateType + "成功",
                            type: "success",
                            showConfirmButton: true,
                            confirmButtonText: '确定'
                        }, function () {
                            arg.successCall(data);
                        });
                    } else {
                        arg.successCall(data);
                    }
                } else {
                    arg.errorCall(data);
                }
            },
            error: function () {
                alert("系统异常.....");
            }, complete: function (data) {
                arg.completeCall(data);
            }
        };

        if (var_arg.contentFile == true) {
            i['contentType'] = false;
            i['processData'] = false;
        }
        if (arg.showWarnAlert) {
            swal({
                    title: '确定' + arg.operateType,
                    type: "warning",
                    showCancelButton: true,
                    cancelButtonText: "取消",
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: '确定',
                    closeOnConfirm: false
                },
                function () {
                    $.ajax(i);
                });
        } else {
            $.ajax(i);
        }
    },
    errorCallBack: function (data, arg) {

        if (typeof arg.errorAddress != 'undefined') {
            arg.errorAddress.html($.sysPlugin.createAlert(data.message));
        }

        if (typeof arg.form != 'undefined') {
            arg.form.data('bootstrapValidator').resetForm();
        }
    },
    successCallBack: function (data, arg) {
        if (typeof arg.modal != 'undefined') {
            arg.modal.modal('hide');
        }
        if (typeof arg.form != 'undefined') {
            arg.form.data('bootstrapValidator').resetForm();
        }

        if (typeof arg.table != 'undefined') {
            arg.table.bootstrapTable('refresh');
        }
        if (typeof arg.jsTree == 'function') {
            arg.jsTree();
        } else if (typeof arg.jsTree != 'undefined') {
            arg.jsTree.jstree('refresh');
        }

    }

};

(function ($) {
    $.fn.serializeObject = function () {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function () {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
})(jQuery);


//zTree 扩展 START
function ApmZTreeUtil(showInput, picker, render) {
    this.beforeClick = function (treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj(render.attr("id"));
        zTree.checkNode(treeNode, !treeNode.checked, true, true);
        return false;
    };
    this.onCheck = function (e, treeId, treeNode) {
        var zTree = $.fn.zTree.getZTreeObj(render.attr("id")),
            nodes = zTree.getCheckedNodes(true),
            v = "";
        for (var i = 0, l = nodes.length; i < l; i++) {
            v += nodes[i].name + ",";
        }
        if (v.length > 0) v = v.substring(0, v.length - 1);
        var cityObj = showInput;
        cityObj.attr("value", v);

        try {
            cityObj.parents("form").bootstrapValidator('revalidateField', cityObj.attr('name'));
        } catch (e) {
        }


    };
    this.showMenu = function () {
        picker.slideDown("fast");
        $("body").bind("mousedown", this.onBodyDown);
    };
    this.onBodyDown = function (event) {
        if (!( event.target == showInput || event.target == picker || $(event.target).parents("#" + picker.attr("id")).length > 0)) {
            picker.fadeOut("fast");
            $("body").unbind("mousedown", this.onBodyDown);
        }
    };


}

//<input type="text" readonly id="citySel1" class="form-control" name="permission">
//    <div id='menuContent1' style="display: none; position: relative; height: 0px;z-index: 100">
//    <div style="background-color: #f5f5f5;border: 1px solid #ccc">
//    <div style="overflow-y:auto; overflow-x:auto; max-height: 200px; ">
//    <ul id="treeDemo1" class="ztree"></ul>
//    </div>
//    </div>
//    </div>
//
//$(function () {
//    var selectTree = new ApmZTreeUtil(
//        $("#citySel1"),
//        $("#menuContent1"),
//        $("#treeDemo1")
//    ), setting = {
//        check: {
//            enable: true,
//            checkboxType: {"Y": "", "N": ""}
//        },
//        view: {
//            dblClickExpand: false
//        },
//        data: {
//            simpleData: {
//                enable: true
//            }
//        },
//        async: {
//            enable: true,
//            url:$("#id").val() == ''?"upms/permission/selectChildren":"upms/permission/selectByRoleId",
////                autoParam: ["id"],
//            otherParam:{"id":$("#id").val()},
////                dataFilter: filter
//        },
//        callback: {
//            beforeClick: selectTree.beforeClick,
//            onCheck: selectTree.onCheck
//        }
//    };
//    $("#citySel1").on('click', function () {
//        selectTree.showMenu();
//    });
//    $.fn.zTree.init($("#treeDemo1"), setting);
//});

//zTree 扩展 END


//插件汉化包    START
(function ($) {
    $.fn.datetimepicker.dates['zh-CN'] = {
        days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"],
        daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
        daysMin: ["日", "一", "二", "三", "四", "五", "六", "日"],
        months: ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"],
        monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十1月", "十一月", "十二月"],
        today: "今天",
        suffix: [],
        meridiem: ["上午", "下午"]
    };
}(jQuery));

!function (a) {
    "use strict";
    a.fn.bootstrapTable.locales["zh-CN"] = {
        formatLoadingMessage: function () {
            return "正在努力地加载数据中，请稍候……"
        }, formatRecordsPerPage: function (a) {
            return "每页显示条数：" + a + ""
        }, formatShowingRows: function (a, b, c) {
            return ""
        }, formatSearch: function () {
            return "搜索"
        }, formatNoMatches: function () {
            return "没有找到匹配的记录"
        }, formatPaginationSwitch: function () {
            return "隐藏/显示分页"
        }, formatRefresh: function () {
            return "刷新"
        }, formatToggle: function () {
            return "切换"
        }, formatColumns: function () {
            return "列"
        }, formatExport: function () {
            return "导出数据"
        }, formatClearFilters: function () {
            return "清空过滤"
        }
    }, a.extend(a.fn.bootstrapTable.defaults, a.fn.bootstrapTable.locales["zh-CN"])
}(jQuery);
//插件汉化包    END